// 引入异步对象
import request from "@/utils/request"

// 2. 使用枚举来存储接口
enum Api {
  // 根据spuId 获取sku数据
  getSkuListApi = "/admin/product/findBySpuId",
  // 添加SkuInfo
  saveSkuInfoApi = "/admin/product/saveSkuInfo",
  // 删除
  DeleteSkuApi = "/admin/product/deleteSku",
  // 获取图片
  GetSpuImageList = "/admin/product/spuImageList",
  // 获取分页数据
  GetSkuList = "/admin/product/list",
  // 获取详情
  GetSkuInfo = "/admin/product/getSkuById",
  // 上架
  OnSale = "/admin/product/onSale",
  // 下架
  CancelSale = "/admin/product/cancelSale",
}

// 添加SkuInfo数据
export const reqSaveSkuInfo = (skuInfo) => {
  return request.post<any, any>(Api.saveSkuInfoApi, skuInfo)
}

// 根据spuId获取sku列表
export const reqGetSkuListData = (spuId: number) => {
  return request.get<any, any>(Api.getSkuListApi + `/${spuId}`)
}

// 删除
export const reqDeleteSku = (skuId: number) => {
  return request.delete<any, any>(Api.DeleteSkuApi + `/${skuId}`)
}

// 获取图片
export const reqGetSpuImageList = (spuId: number) => {
  return request.get<any, any>(Api.GetSpuImageList + `/${spuId}`)
}

// 获取SKU分页数据
export const getSkuListApi = (page: number, limit: number) => {
  return request.get<any, any>(Api.GetSkuList + `/${page}/${limit}`)
}

// 上架
export const onSaleApi = (skuId: number) => {
  return request.get<any, null>(Api.OnSale + `/${skuId}`)
}

// 下架
export const cancelSaleApi = (skuId: number) => {
  return request.get<any, null>(Api.CancelSale + `/${skuId}`)
}

// 获取详情
export const getSkuInfoApi = (skuId: number) => {
  return request.get<any, any>(Api.GetSkuInfo + `/${skuId}`)
}
